<style lang="less" scoped>
.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  .swiper {
    flex: 1;
    &-item {
      overflow-y: auto;
    }
  }
}
.panel {
  margin-bottom: 10px;
  &-title {
    display: flex;
    padding: 10px;
    border-bottom: 0.1px solid #eaeaea;
    background: white;

    &__label {
      flex: 1;
      font-size: 16px;
      align-items: center;
    }
  }
  &-content {
    margin-bottom: 10px;
    background: white;
    display: flex;
    &__dec {
      flex: 1;
    }
    &__arrow {
      display: flex;
      align-items: center;
    }
    &__item {
      display: flex;
      padding: 10px 10px 0 10px;
      font-size: 14px;
      &-label {
        color: #666;
      }
      &-value {
        flex: 1;
        padding-left: 15px;
        color: #333;
      }
    }
  }
}
</style>

<template>
  <div class="page">
    <!-- tab-title -->
    <scroll-tab v-if="tabs.length>0" :activeIndex="activeIndex" :tabs="tabs" @indexChange="indexChange" />

    <!-- swiper -->
    <div class="info" v-if="items&&items.length==0">暂无数据</div>

    <swiper class="swiper" @change="swiperChange" :current="activeIndex">
      <swiper-item v-for="(item, index) in items" :key="index" class="weui-tab__content swiper-item">
        <div class="panel">
          <template v-for="(item1, index1) in item.item" wx:key="unique">
            <div class="panel-content" :key="'content'+index1" @click="itemClick(item1.Type)">
              <div class="panel-content__dec">
                <div class="panel-content__item">
                  <div class="panel-content__item-label"></div>
                  <div class="panel-content__item-value">{{item1.Name||'-'}}</div>
                  <div class="panel-content__item-right"></div>
                </div>
                <div class="panel-content__item">
                  <div class="panel-content__item-label"></div>
                  <div class="panel-content__item-value">{{item1.Organization||'-'}}</div>
                  <div class="panel-content__item-right"></div>
                </div>
                <div class="panel-content__item">
                  <div class="panel-content__item-label"></div>
                  <div class="panel-content__item-value">{{item1.SubTitle||'-'}}</div>
                  <div class="panel-content__item-right"></div>
                </div>
              </div>
              <div class="panel-content__arrow">
                <i class="iconfont icon-more"></i>
              </div>
            </div>

          </template>
        </div>
      </swiper-item>
    </swiper>
  </div>
</template>
<script>
import ScrollTab from '@/components/ScrollTab';

export default {
  components: {
    ScrollTab
  },
  data() {
    return {
      activeIndex: 0,
      tabs: [],
      items: [
        {
          category: '其它',
          item: [
            {
              IconUrl:
                'http://eciapp.oss-cn-qingdao.aliyuncs.com/certificate/common_new.png',
              Name: '互联网药品信息',
              NationalCount: '7931',
              Organization: '国家食品药品监督管理总局',
              SubTitle: '全国共有7931家企业拥有此类证书',
              Type: 'C_997_42'
            }
          ]
        },
        {
          category: 'CNCNA证书',
          item: [
            {
              IconUrl:
                'http://eciapp.oss-cn-qingdao.aliyuncs.com/certificate/common_new.png',
              Name: '所有未列明的其他管理体系认证',
              NationalCount: '1',
              Organization: null,
              SubTitle: '全国共有1家企业拥有此类证书',
              Type: 'cnca011'
            }
          ]
        }
      ]
    };
  },
  onLoad() {
    this.getInfos();
  },
  onUnload() {
    this.items = [];
  },
  methods: {
    swiperChange(e) {
      // swiper切换
      this.activeIndex = e.mp.detail.current;
    },
    indexChange(index) {
      // tab切换
      this.activeIndex = index;
    },
    async getInfos() {
      // 获取列表
      const url = '/xcx/getCertificationSummary';
      const params = {
        companyName: this.$root.$mp.page.options.searchKey
      };
      const res = await this.$http.get(url, params);
      if (res.status != 200) {
        wx.showToast({
          title: res.message || '获取失败！',
          icon: 'none',
          mask: true
        });
        return;
      }
      this.items = res.result.Result;
      this.setTabs();
    },
    setTabs() {
      if (!this.items) return [];
      const tabs = this.items.map(item => item.category);
      this.tabs = tabs;
    },
    itemClick(certCategory) {
      this.$router.push({
        path: '/pages/other/zhengshu/list/main',
        query: {
          certCategory,
          searchKey: this.$route.query.searchKey
        }
      });
    }
  }
};
</script>
